#include<bits/stdc++.h>
using namespace std;
bool st;
const int N = 1e6+5;
int n,dep[N*5],sz[N*5],son[N*5][2],cnt = 1;
string s;
void insert()
{
	int p = 1;
	for(auto i:s)
	{
		int w = i-'0';
		if(!son[p][w]) dep[son[p][w] = ++cnt] = dep[p]+1;
		p = son[p][w];
	}
	sz[p]++;
}
set<pair<int,int>> s1[N],s2[N];
int ans;
bool en;
void dfs(int u)
{
	if(!u) return;
//	cerr<<"dfs"<<u<<":"<<son[u][0]<<' '<<son[u][1]<<'\n';
	dfs(son[u][0]),dfs(son[u][1]);
	for(auto _:s1[son[u][0]]) s1[u].insert(_);
	for(auto _:s2[son[u][0]]) s2[u].insert(_);
	for(auto _:s1[son[u][1]]) s1[u].insert(_);
	for(auto _:s2[son[u][1]]) s2[u].insert(_);
	if(!son[u][0]&&!son[u][1]) s2[u].insert({dep[u],u});
	else if(!son[u][0]||!son[u][1]) s1[u].insert({dep[u],u});
//	cout<<"dfs"<<u<<' '<<cnt<<'\n';
//	cout<<"s1:";for(auto _:s1[u]) cout<<_.second<<' ';cout<<'\n';
//	cout<<"s2:";for(auto _:s2[u]) cout<<_.second<<' ';cout<<'\n';
	while(sz[u]&&(son[u][0]||son[u][1]||sz[u]>=2))
	{
//		cout<<"down\n";
		if(s1[u].size()&&s1[u].begin()->first+1<s2[u].begin()->first+2)
		{
			int p = s1[u].begin()->second;s1[u].erase(s1[u].begin());
//			cerr<<"xx"<<p<<'\n';
			ans+=dep[p]-dep[u]+1;
//			assert(dep[p]-dep[u]<=20);
			if(!son[p][0])
			{
				dep[son[p][0] = ++cnt] = dep[p]+1;
				s2[u].insert({dep[cnt],cnt});
			}
			else
			{
				dep[son[p][1] = ++cnt] = dep[p]+1;
				s2[u].insert({dep[cnt],cnt});
			}
		}
		else
		{
			int p = s2[u].begin()->second;s2[u].erase(s2[u].begin());
//			cerr<<"yy"<<p<<'\n';
			ans+=dep[p]-dep[u]+2;
//			assert(dep[p]-dep[u]<=20);
			
			dep[son[p][0] = ++cnt] = dep[p]+1;
			s2[u].insert({dep[cnt],cnt});
			
			dep[son[p][1] = ++cnt] = dep[p]+1;
			s2[u].insert({dep[cnt],cnt});
			sz[p]--;
		}
//		cout<<ans<<'\n';
		sz[u]--;
	}
//	cerr<<"ok"<<u<<'\n';
}
signed main()
{
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cerr<<(&st-&en)/1024/1024<<'\n';
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>s,insert();
	dfs(1);
	cout<<ans;
	return 0;
}

